local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHScreenBase());
local CommonOHOH =_G.CommonOHOH
local CallBackManager = ClientOHOH.load.CallBackManager();
local BtnHelper = ClientOHOH.load.BtnHelper();
local LanguageHelper=_G.LanguageHelper 
local ConnectClass=CommonOHOH.load.Connect();


function InitInsts(ui)
	ui.insts = {};
	ui.insts.root ="Frame.Frame"
	ui.insts.close ="Frame.Frame.close"

	ui.insts.pay1 ={
        price="Frame.Frame.Price1.Robux",
        count="Frame.Frame.Price1.num",
        btn="Frame.Frame.Price1",
    }

	ui.insts.pay2={
        price="Frame.Frame.Price2.Robux",
        count="Frame.Frame.Price2.num",
        btn="Frame.Frame.Price2",
    }

    ui.insts.probability={}
    ui.insts.boost={}
    ui.insts.list="Frame.Frame.list.Frame"
    
    -- for i=1,3 do
    --     table.insert(ui.insts.boost,"Frame.Frame.list.Frame."..i..".num")
    --     table.insert(ui.insts.probability,"Frame.Frame.list.Frame."..i..".probability")
    -- end
    
    ui.insts.EggName="Frame.Frame.list.EggName"

end

function M.MobileSize(self)
	if _G.client.IsMobile then --是移动设备
		if self.insts.root then
			local pos= self.insts.root:GetAttribute("Position")
			local size=self.insts.root:GetAttribute("Size")

			if pos then
				self.insts.root.Position=pos
			end
			if size then
				self.insts.root.Size=size
			end
		end
	end
end

function M.new(...)
	return M(...);
end;
function M.ctor(self,gui,eggName,probability,boost,price1,price2,count1,count2)
	InitInsts(self)

	M.super.ctor(self,gui);

	self:MobileSize()


	CallBackManager:AddRbxConnect(self,self.insts.close.Activated, function()
		self:Hide()
	end);
	
    self.Pay1Event=ConnectClass.new()
    self.Pay2Event=ConnectClass.new()

    CallBackManager:AddRbxConnect(self,self.insts.pay1.btn.Activated, function()
        self.Pay1Event:Action()
	end);

    CallBackManager:AddRbxConnect(self,self.insts.pay2.btn.Activated, function()
        self.Pay2Event:Action()
	end);

	self:AddProcess(function()
		for _, v in pairs(self.main_inst:GetDescendants()) do
			if v:IsA("GuiButton") then
				BtnHelper:InitButton(v, nil, nil, nil, function() end);
			end;
		end;
	end);
	
    self:InitEggInfo(eggName,probability,boost,price1,price2,count1,count2)

end;



function M.InitEggInfo(self,eggName,probability,boost,price1,price2,count1,count2)

    local count=#probability
    self.insts.boost={}
    self.insts.probability={}
    for i=1,count do
        table.insert(self.insts.boost,  ClientOHOH:GetPath_Loop(i..".num",self.insts.list))
        table.insert(self.insts.probability, ClientOHOH:GetPath_Loop(i..".probability",self.insts.list))
    end


    self.insts.EggName.Text=eggName

    self.insts.pay1.price.Text=price1
    self.insts.pay1.count.Text="x"..count1

    self.insts.pay2.price.Text=price2
    self.insts.pay2.count.Text="x"..count2

    self.insts.EggName.Text=eggName

    for k,v in pairs(probability) do
        self.insts.probability[k].Text= string.format("%.2f",v) .."%"
    end
 
    for k,v in pairs(boost) do
        self.insts.boost[k].Text=v
    end
end

function M.dtor(self)
	M.super.dtor(self);
end;



return M
